//
//  YFMessageTableViewController.swift
//  微博
//
//  Created by 余仿 on 16/4/6.
//  Copyright © 2016年 YF. All rights reserved.
//

import UIKit

class YFMessageTableViewController: YFGuideTableViewController {


    override func viewDidLoad() {

        super.viewDidLoad()

        setupUI()

    }

    func findQun(){
        
        print("findQun")

        tabBarItem.badgeValue = nil

        tabBarItem.badgeValue = "\(random() % 30)"

    }


    func setupUI(){

        if !isLogIn{

            guideView?.setupUI("visitordiscover_image_message", desc: "太阳出来爬山坡,爬上了山坡我想唱歌,")
        }else{

            print(tabBarItem)

            print(tabBarItem)


            navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: nil, title: "发现群", target: self, action: "findQun")

            tabBarItem.badgeValue = "\(random() % 30)"

//            setBadgeView()
        }
    }

    //MARK:自定义BadgeValue的UIImage
    func setBadgeView(){

        for subView in (tabBarController?.tabBar.subviews)!{

            if subView.isKindOfClass(NSClassFromString("UITabBarButton")!){

                for sub in subView.subviews{

                    if sub.isKindOfClass(NSClassFromString("_UIBadgeView")!){

                        for s in sub.subviews{

                            if s.isKindOfClass(NSClassFromString("_UIBadgeBackground")!){

                                s.setValue(UIImage(named: "main_badge"), forKey: "_image")
                            }
                        }

                    }
                }
            }
        }
    }
}
